VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmBasicMIDeliveryReceipt 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   6645
   ClientLeft      =   2070
   ClientTop       =   630
   ClientWidth     =   12285
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   6645
   ScaleWidth      =   12285
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ITGTab SSTab1 
      Height          =   2595
      Left            =   30
      TabIndex        =   12
      Top             =   30
      Width           =   11790
      _ExtentX        =   20796
      _ExtentY        =   4577
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   1
      Tab(0)ContCtrlCap(1)=   "ComunionFrames1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   16243138
      DisabledTabForeColor=   -2147483627
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   3480
         Left            =   -75000
         TabIndex        =   11
         Top             =   315
         Width           =   11790
         _ExtentX        =   20796
         _ExtentY        =   6138
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   7
         BeginProperty Column00 
            DataField       =   "cDRNo"
            Caption         =   "Receipt No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cDelCode"
            Caption         =   "Client ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cType"
            Caption         =   "Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "dReceived"
            Caption         =   "Received Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "dReturned"
            Caption         =   "Returned Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "cRemarks"
            Caption         =   "Remarks"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1544.882
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1395.213
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   1335.118
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   1544.882
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   1395.213
            EndProperty
            BeginProperty Column05 
               Locked          =   -1  'True
               ColumnWidth     =   1425.26
            EndProperty
            BeginProperty Column06 
               Locked          =   -1  'True
               ColumnWidth     =   2520
            EndProperty
         EndProperty
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   2280
         Left            =   0
         Top             =   360
         Width           =   11790
         _ExtentX        =   20796
         _ExtentY        =   4022
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Delivery Receipt Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.CommandButton cmdPickWork 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   3000
            Picture         =   "frmBasicMIDeliveryReceipt.frx":0000
            Style           =   1  'Graphical
            TabIndex        =   25
            Top             =   1455
            Width           =   315
         End
         Begin VB.CommandButton cmdPickProject 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   3000
            Picture         =   "frmBasicMIDeliveryReceipt.frx":014A
            Style           =   1  'Graphical
            TabIndex        =   22
            Top             =   1155
            Width           =   315
         End
         Begin VB.CommandButton cmdPickDelCode 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   3000
            Picture         =   "frmBasicMIDeliveryReceipt.frx":0294
            Style           =   1  'Graphical
            TabIndex        =   4
            Top             =   855
            Width           =   315
         End
         Begin VB.ComboBox cboType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmBasicMIDeliveryReceipt.frx":03DE
            Left            =   9675
            List            =   "frmBasicMIDeliveryReceipt.frx":0400
            Style           =   2  'Dropdown List
            TabIndex        =   2
            Top             =   540
            Width           =   1395
         End
         Begin VB.Timer Timer1 
            Interval        =   300
            Left            =   2985
            Top             =   390
         End
         Begin ITGControls.ITGTextBox txtDRNo 
            Height          =   285
            Left            =   165
            TabIndex        =   0
            Top             =   555
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Receipt No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtDelName 
            Height          =   285
            Left            =   3300
            TabIndex        =   5
            TabStop         =   0   'False
            Top             =   855
            Width           =   4245
            _ExtentX        =   7382
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4185
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtDelCode 
            Height          =   285
            Left            =   165
            TabIndex        =   3
            Top             =   855
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Client"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtRemarks 
            Height          =   285
            Left            =   165
            TabIndex        =   6
            Top             =   1755
            Width           =   7395
            _ExtentX        =   12832
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Remarks"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   6085
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGTextBox txtInvNo 
            Height          =   285
            Left            =   8385
            TabIndex        =   9
            TabStop         =   0   'False
            Top             =   1470
            Width           =   2565
            _ExtentX        =   4313
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Invoice No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1260
            TextBoxWidth    =   1245
            Enabled         =   0   'False
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   5790
            TabIndex        =   1
            Tag             =   "Delivery Date"
            Top             =   555
            Width           =   1320
            _ExtentX        =   2328
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
         End
         Begin ITGControls.ITGDateBox dtbReceived 
            Height          =   285
            Left            =   9675
            TabIndex        =   7
            Top             =   870
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
         End
         Begin ITGControls.ITGDateBox dtbReturned 
            Height          =   285
            Left            =   9675
            TabIndex        =   8
            Top             =   1170
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtType 
            Height          =   285
            Left            =   9735
            TabIndex        =   13
            Tag             =   "cboType"
            Top             =   555
            Visible         =   0   'False
            Width           =   1005
            _ExtentX        =   1667
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "DR Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   945
         End
         Begin ITGControls.ITGTextBox txtODI 
            Height          =   285
            Left            =   8400
            TabIndex        =   21
            Top             =   1800
            Visible         =   0   'False
            Width           =   2565
            _ExtentX        =   4313
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "ODI No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1255
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtProjectName 
            Height          =   285
            Left            =   3300
            TabIndex        =   23
            TabStop         =   0   'False
            Top             =   1155
            Width           =   4245
            _ExtentX        =   7382
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4185
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtProject 
            Height          =   285
            Left            =   165
            TabIndex        =   24
            Top             =   1155
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Project"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtWorkDesc 
            Height          =   285
            Left            =   3300
            TabIndex        =   26
            TabStop         =   0   'False
            Top             =   1455
            Width           =   4245
            _ExtentX        =   7382
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   4185
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtWork 
            Height          =   285
            Left            =   165
            TabIndex        =   27
            Top             =   1455
            Width           =   2805
            _ExtentX        =   4736
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Work"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1495
            Required        =   -1  'True
            LinkForeColor   =   16711680
         End
         Begin VB.Label Label5 
            BackStyle       =   0  'Transparent
            Caption         =   "Date"
            Height          =   345
            Left            =   5250
            TabIndex        =   17
            Top             =   600
            Width           =   720
         End
         Begin VB.Label Label4 
            BackStyle       =   0  'Transparent
            Caption         =   "Returned Date"
            Height          =   345
            Left            =   8400
            TabIndex        =   16
            Top             =   1200
            Width           =   1200
         End
         Begin VB.Label Label3 
            BackStyle       =   0  'Transparent
            Caption         =   "Received Date"
            Height          =   345
            Left            =   8400
            TabIndex        =   15
            Top             =   885
            Width           =   1200
         End
         Begin VB.Label Label1 
            BackStyle       =   0  'Transparent
            Caption         =   "DR Type"
            Height          =   345
            Left            =   8400
            TabIndex        =   14
            Top             =   600
            Width           =   720
         End
      End
   End
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   285
      Left            =   0
      TabIndex        =   18
      Top             =   6360
      Width           =   12285
      _ExtentX        =   21669
      _ExtentY        =   503
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   8442
            MinWidth        =   2
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin ITGControls.ComunionFrames ComunionFrames2 
      Height          =   3000
      Left            =   30
      Top             =   2610
      Width           =   11790
      _ExtentX        =   20796
      _ExtentY        =   5292
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Details"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.ComboBox cboDR 
         Height          =   315
         Left            =   4215
         Style           =   2  'Dropdown List
         TabIndex        =   20
         Top             =   1860
         Visible         =   0   'False
         Width           =   1395
      End
      Begin VB.TextBox txtLongDesc 
         Appearance      =   0  'Flat
         DataField       =   "cLongDesc"
         Height          =   1215
         Left            =   150
         MultiLine       =   -1  'True
         TabIndex        =   19
         Top             =   975
         Visible         =   0   'False
         Width           =   3960
      End
      Begin MSDataGridLib.DataGrid dtgDR 
         Height          =   2580
         Left            =   0
         TabIndex        =   10
         Top             =   420
         Width           =   11790
         _ExtentX        =   20796
         _ExtentY        =   4551
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   13
         BeginProperty Column00 
            DataField       =   "cRefNo"
            Caption         =   "Reference No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cDesc"
            Caption         =   "Product Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cCosting"
            Caption         =   "Costing"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cWH"
            Caption         =   "Warehouse"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "nPrice"
            Caption         =   "Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.0000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nAmount"
            Caption         =   "Amount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "cBarcodeID"
            Caption         =   "Barcode ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "nCost"
            Caption         =   "Cost"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column11 
            DataField       =   "nRefIdentity"
            Caption         =   "Reference Identity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column12 
            DataField       =   "nFactor"
            Caption         =   "Factor"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   13321
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Locked          =   -1  'True
               ColumnWidth     =   1094.74
            EndProperty
            BeginProperty Column01 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1230.236
            EndProperty
            BeginProperty Column02 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   2204.788
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   854.929
            EndProperty
            BeginProperty Column04 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1335.118
            EndProperty
            BeginProperty Column05 
               Locked          =   -1  'True
               ColumnWidth     =   615.118
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               ColumnWidth     =   959.811
            EndProperty
            BeginProperty Column07 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1080
            EndProperty
            BeginProperty Column08 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   -1  'True
               ColumnWidth     =   1335.118
            EndProperty
            BeginProperty Column09 
               Button          =   -1  'True
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1214.929
            EndProperty
            BeginProperty Column10 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column11 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column12 
               Object.Visible         =   0   'False
               ColumnWidth     =   60.094
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmBasicMIDeliveryReceipt"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'Object variables
Private oPrint As New clsPrinting

Private AutoNum As New clsAutoNumber '---Added
Public MenuName As String '---Added


'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset

'ADO Connection variables

Private connHeader As ADODB.Connection
Private connDetail As ADODB.Connection

'Form mode enumeration
Enum eBasicDRMode
    Normal
    AddNewEdit
    Find
End Enum
Public Mode As eBasicDRMode

'Other declarations
Public dtgName As String
Public sBit As String

Private lSystemGenerated As Boolean
Public strNo As String

Private vBM As Variant 'Recordset bookmark variable
Public X As String, sType As String

Private nLimit, nAR, nARPastDue, nPDC, nHold, nBounced, nSOAmtLeft, nLimitBalance As Double 'For credit limit purposes
Private lOverride As Boolean

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Public lAllowCost As Boolean
Private lSysTransDate As Boolean 'add by denz:2/17/2011 for transdate

Private Sub cboDocType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboDR_Click()
    If dtgDR.Col = 4 Then
        rsDetail!cWH = cboDR
    End If
End Sub

Private Sub cboDR_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgDR.Col = 4 Then
            rsDetail!cWH = cboDR
            cboDR.Visible = False
            dtgDR.Col = 6
            dtgDR.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboDR.Visible = False
    End If
End Sub

Private Sub cboDR_LostFocus()
    cboDR.Visible = False
End Sub

Private Sub cboType_Click()
'    If Trim(cboType) = "Purchase Return" Then
'        EditDetail_Others True
'    ElseIf Trim(cboType) = "Others" Then
'        EditDetail_Others True
''    ElseIf Trim(cboType) = "Issues" Then
''        cboDocType = "Doc 1"
''    ElseIf Trim(cboType) = "Sales" Then
''        cboDocType = "Doc 2"
'    Else: EditDetail_Others False
'    End If
    txtType = Trim(cboType)
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.EOF
            rsDetail.Delete
            rsDetail.MoveNext
        Loop
    End If
    EditDetail True
End Sub

Sub EditDetail_Others(bval As Boolean)
    dtgDR.Columns(1).Locked = Not bval
    dtgDR.Columns(1).Button = bval
End Sub

Private Sub cboType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboType_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If UCase(Trim(txtType)) = "AUTO-DR" Then
        MsgBox "DR type Auto-DR are auto-generated.", vbInformation, msgTtl
        cboType.SetFocus
    End If
End Sub

Private Sub cmdLoad_Click()
    
    If Mode <> AddNewEdit Then Exit Sub
    
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbInformation, msgTtl
        cboType.SetFocus
        Exit Sub
    End If
    
    If Trim(txtDelCode) = "" Then
        Select Case UCase(Trim(cboType))
            Case "PRODUCTION-OS"
            Case "PRODUCTION-INT"
            Case Else
                MsgBox "Please input customer ID.", vbInformation, msgTtl
                txtDelCode.SetFocus
                Exit Sub
        End Select
    End If
        
    RepName = Trim(txtDelCode)
    
    Select Case Trim(cboType)
        Case "Issues", "Sales"
            sCondition = "'" & COID & "', '" & Trim(txtDelCode) & "', ' and a.cType = ''Regular'''"
            frmRefList.mType = DR_Issues
        Case "Production", "Production-OS"
            sCondition = "'" & COID & "', '" & Trim(txtDelCode) & "', ' '"
            frmRefList.mType = DR_Production
        Case "Purchase Return"
            sCondition = "'" & COID & "', '" & Trim(txtDelCode) & "', ' '"
            frmRefList.mType = DR_PurchaseReturn
        Case "Others"
    End Select
    If frmRefList.Visible = False Then frmRefList.Show vbModal

End Sub

Private Sub cmdPickDelCode_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtDelCode)
    With frmITGPicker
        If Trim(cboType) = "Purchase Return" Then
            .zType = QSupplier
        ElseIf Trim(cboType) = "Production-OS" Then
            .zType = QSupplier
        ElseIf Trim(cboType) = "Production-Int" Then
            .zType = QSupplier
        Else: .zType = QCustomer
        End If
        'added condition
        .Condition = "where cCompanyID = '" & COID & "'"
        .Show vbModal
        txtDelCode = .zCode
End With
End Sub

Private Sub cmdPrintTransmital_Click()
If rsHeader.RecordCount = 0 Then Exit Sub
    If Trim(txtDRNo) = "" Or Trim(cboType) <> "Consignment" Then Exit Sub
    cModule = "Transmittal_Report"
    oPrint.PrintReceipt Trim(txtDRNo)
End Sub

Private Sub dtbReturned_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then TBNewLine
End Sub

Private Sub dtgDR_AfterColUpdate(ByVal ColIndex As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 1
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgDR.Columns(1).Value) & "'") <> "" Then
                GetInitialItemValues rsDetail
                dtgDR.Col = 6
                dtgDR.Columns(6).Value = IIf(IsNull(rsDetail!nQty), 0, rsDetail!nQty)
            End If
        Case 6
            ComputeAmount
            ComputeTotal
        Case 7
            ComputeAmount
            ComputeTotal
    End Select
    
End Sub

Private Sub dtgDR_ButtonClick(ByVal ColIndex As Integer)
    
If ColIndex = 2 Then
    Call MoveText(txtLongDesc, dtgDR, dtgDR.Columns(2))
    txtLongDesc = rsDetail!cLongDesc & ""
End If
If Mode <> AddNewEdit Then 'Exit Sub
    Select Case ColIndex
        Case 1
            Select Case Trim(cboType)
                Case "Purchase Return"
                    If lPickListActive Then Exit Sub
                    sFilterString = Trim(dtgDR.Columns(1).Text)
                    frmITGPicker.zType = QProduct
                    'added condition
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
                    
                    frmITGPicker.Show vbModal
                    rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                    If (Trim(frmITGPicker.zName) & "") <> "" Then
                        GetInitialItemValues rsDetail
                        dtgDR.Col = 6
                        dtgDR.Columns(6).Value = 0
                    End If
                Case "Others"
                    If lPickListActive Then Exit Sub
                    sFilterString = Trim(dtgDR.Columns(1).Text)
                    frmITGPicker.zType = QProduct
                    'added condition
                    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
                    
                    frmITGPicker.Show vbModal
                    rsDetail!cItemNo = Trim(frmITGPicker.zCode) & ""
                    If (Trim(frmITGPicker.zName) & "") <> "" Then
                        GetInitialItemValues rsDetail
                        dtgDR.Col = 6
                        dtgDR.Columns(6).Value = 0
                    End If
                Case Else
                    Exit Sub
            End Select
'        Case 4
        Case 9
            GetBarcode
    End Select
Else
    Select Case ColIndex
        Case 1
            If Mode <> Find Then
                If Trim(dtgDR.Columns(1).Text) <> "" Then
                End If
            End If
        Case 4
            Call LoadComboValues(cboDR, "cWH", "WHSE", "WHERE cCompanyID = '" & COID & "'")
            Call MoveCombo(cboDR, dtgDR, dtgDR.Columns(4))
            ComboLoadValue cboDR, Trim(dtgDR.Columns(4).Text)
        Case 9
            GetBarcode
    End Select
End If
End Sub

'Set the datagrid as active control
Private Sub dtgDR_Click()
    If Mode = AddNewEdit Then dtgName = dtgDR.Name
End Sub

Private Sub dtgDR_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgDR_GotFocus()
    dtgName = dtgDR.Name
End Sub

Private Sub dtgDR_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgDR_KeyPress(KeyAscii As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    
    If KeyAscii = 13 Then
        Select Case dtgDR.Col
            Case 1
                If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgDR.Columns(1).Value) & "'") = "" Then
                    dtgDR_ButtonClick (1) 'use button click
                End If
            Case 6
                Select Case Trim(cboType)
                    Case "Others"
                        rsDetail!nQty = dtgDR.Columns(6).Value
                        dtgDR_AfterColUpdate (6)
                        TBNewLine
                        dtgDR.LeftCol = 0
                    Case Else
                        rsDetail!nQty = dtgDR.Columns(6).Value
                        dtgDR_AfterColUpdate (6)
                        dtgDR.Col = 9
                        dtgDR.Columns(9).Value = rsDetail!cBarcodeID
                End Select
'            Case 6
'                rsDetail!nQty = dtgDR.Columns(6).Value
'                dtgDR_AfterColUpdate (6)
'                dtgDR.Col = 9
'                dtgDR.Columns(9).Value = rsDetail!cBatchID
            Case 8
                GetBarcode
            Case Else
                SendKeys "{Tab}"
        End Select
    Else: KeyAscii = Asc(UCase(Chr(KeyAscii)))       'All Upper Case String
    End If

End Sub

'Right click menu popup
Private Sub dtgDR_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgDR.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()
    Set FrmName = Me
    FormSetup
    
    If Not lAllowCost Then
        dtgDR.Columns(7).Visible = False
        dtgDR.Columns(8).Visible = False
        AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'BMI03'")
    Else: AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'BMI03'")
    End If
    
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    

    'Load combobox values
    sSQL = "(SELECT module_id FROM erp_sec_modules WHERE link = '" & Me.Name & "')"
    Call LoadComboValues(cboType, "RefType", "ComboValueSetUp", "Where RefModule = " & sSQL & " AND Visible = 1 and cCompanyID = '" & Trim(COID) & "'")

    Set FrmName = Me
    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    
    Mode = Find
    txtDRNo.Locked = False
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
    
    Set oPrint = Nothing
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set connHeader = Nothing
    Set connDetail = Nothing

    Set frmBasicMIDeliveryReceipt = Nothing
    
    lCloseWindow = True
    
    'oForm(Me.Tag).Mode = 1
    'oForm(Me.Tag).Tag = Me.Tag
End Sub

'Add new record to the recordset
Public Sub TBNew()

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtDRNo.BackColor = &HE0FFFF
    Mode = AddNewEdit

    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connHeader
        OpenNewConnection connDetail
        OpenRecordsetWithCN rsDetail, "*", "DR_T", connDetail, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "DR", connHeader, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else
        vBM = rsHeader.Bookmark
    End If
        
    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!dDate = Date
    cboType.Text = "Issues"
    rsHeader!cPCCode = sDivision

    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    SSTab1.ActiveTab = 0
    'txtDRNo.Locked = True 'Add by denz:1/18/2011
    txtDRNo.SetFocus

    MenuName = "AUTO_NUMBER_DR"
    lSystemGenerated = GetValueFrTable("lAutoNo", "system_autonumber", "cCode = '" & MenuName & "' ")
    If lSystemGenerated Then rsHeader!cDRNo = AutoNum.Generate_CtrlNo2(MenuName, Format(Now, "mm/dd/yyyy"))
    
    strNo = rsHeader!cDRNo

End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsDetail.CancelBatch adAffectAll
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True
    Else
        RSZero
        Mode = Find
    End If

    sbRS.Panels(2) = ""
    
    SetDataSource
    SetDataField
    
    EditDetail False

ErrorHandler:

    cboDR.Visible = False
    
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    GetChild
    If rsHeader.Status = adRecNew Then
        rsDetail.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsDetail.CancelBatch adAffectAll
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
On Error GoTo ErrHandler

    'Audit Trail
    lBoolean = False
       
    If rsHeader.Status = adRecNew Then
        lBoolean = True
        If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CL_CHECKING_DR'") Then
            If Not lOverride Then
                If (UCase(Trim(cboType)) = "ISSUES") Or (UCase(Trim(cboType)) = "SALES") Then
                    If CDbl(rsHeader!nGross) > (nLimitBalance) Then
                        MsgBox "DR Gross exceeds the allowable credit limit balance." & vbCr & _
                                "Transaction cannot be saved.", vbInformation, msgTtl
                        Exit Sub
                    End If
                End If
            End If
        End If
        If Not BalancePerWarehouseOK Then Exit Sub
    End If
    
    If Not MandatoryOK Then Exit Sub
        
    'System generated number
    If rsHeader.Status = adRecNew Then
        If lSystemGenerated Then
            If ChkCtrlNo(rsHeader, "AUTO_NUMBER_DR", "DR", "cDRNo", rsHeader!cDRNo) <> rsHeader!cDRNo Then
                If AutoNum.Check_CtrlNo2(rsHeader, "DR", "cDRNo", rsHeader!cDRNo, MenuName, rsHeader!dDate) <> rsHeader!cDRNo Then
                    GetChild
                    
                    rsHeader!cDRNo = strNo
                    
                    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
                    Do Until rsDetail.EOF
                        rsDetail!cDRNo = strNo
                        rsDetail.MoveNext
                    Loop
                    
                    GetChild
                End If
            End If
        End If
    End If
    
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    connDetail.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    
    cn.CommitTrans
    connHeader.CommitTrans
    connDetail.CommitTrans
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, False, , , True, lACCancel, , , True, True, lACPrint, True, True
    Mode = Normal
    
    showPostButton
    
    If UCase(Trim(cboType)) = "PRODUCTION-INT" Then Update_Prod_RefNo Trim(txtDRNo)
    If UCase(Trim(cboType)) = "PRODUCTION-OS" Then Update_Prod_RefNo Trim(txtDRNo)
       
    'Audit trail
    UpdateLogFile "Delivery Receipt", Trim(txtDRNo), IIf(lBoolean, "Inserted", "Updated")

    'Update GL Activity
    UpdateGLA "Update", "DR", Trim(txtDRNo)

    'update system generated number
    If lBoolean Then
        If lSystemGenerated And strNo = rsHeader!cDRNo Then
            UpdateControlNo strNo, rsHeader!cDRNo, "AUTO_NUMBER_DR"
            AutoNum.Update_CtrlNo2 strNo, "AUTO_NUMBER_DR", Format(Now, "mm/dd/yyyy")
        End If
    End If
    
    If lBoolean = False Then ' Edit
            cn.Execute ("UPDATE DR SET  dUpdated = GETDATE () WHERE cDRNo = '" & Trim(txtDRNo) & "' AND cCompanyID = '" & COID & "'")
    Else ' Insert
        cn.Execute ("UPDATE DR SET  dUpdated = GETDATE () WHERE cDRNo = '" & Trim(txtDRNo) & "' AND cCompanyID = '" & COID & "'")
    End If
    
    MsgBox "Record/s successfully saved.", vbInformation, msgTtl
    sbRS.Panels(2) = ""
    
    OKUpdate = True
ErrHandler:
    cboDR.Visible = False
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, msgTtl
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, msgTtl
        cn.RollbackTrans
        connHeader.RollbackTrans
        connDetail.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
    showPostButton
End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Edit is not allowed.", vbExclamation, msgTtl
        Exit Sub
    End If
    If Not AllowEdit Then Exit Sub
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtDRNo.Locked = True
    SSTab1.ActiveTab = 0
    dtbDate.SetFocus
    vBM = rsHeader.Bookmark

    MenuName = "AUTO_NUMBER_DR"
    lSysTransDate = GetValueFrTable("lTransDate", "system_autonumber", "cCode = '" & MenuName & "' ") 'add by denz:2/17/2011
    If lSysTransDate Then
        dtbDate.Enabled = True
    Else: dtbDate.Enabled = False
    End If
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler

    sID = Trim(txtDRNo)
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Deletion is not allowed.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub

    If Not AllowDelete("delete") Then Exit Sub
    
    'Update GL Activity
    UpdateGLA "Delete", "DR", Trim(txtDRNo)
    
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    
    'Audit trail
    UpdateLogFile "Delivery Receipt", Trim(txtDRNo), "Deleted"

    rsHeader.Delete adAffectCurrent
    
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    
    TBPrevRec
    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        cn.Execute "DELETE DR_T WHERE cDRNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE DR WHERE cDRNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        Resume Next
    End If
End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtDRNo.Locked = True
    frmITGSearch.Show 'vbModal
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
Dim sTemp As String
If Mode = Find Then
    FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
        
    OpenNewConnection connHeader
    OpenNewConnection connDetail
    
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset

    sTemp = Trim$(GetSearchString)
    If sTemp = "ERROR" Then
        MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
        txtDRNo.Locked = False
        txtDRNo.SetFocus
        Exit Sub
    End If
        
    OpenRecordsetWithCN rsHeader, "*", "DR", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
    OpenRecordsetWithCN rsDetail, "*", "DR_T", connDetail, IIf(sTemp = "", "", " WHERE cDRNo IN (SELECT cDRNo FROM DR WHERE " & sTemp & ")")
        
    Set FrmName = Me
    FormLocking True

    If rsHeader.RecordCount = 0 Then
        FormWaitHide
        MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
        Exit Sub
    End If
    SetDataSource
    SetDataField
    txtDRNo.BackColor = &HE0FFFF
    cboType = txtType.Text
    Mode = Normal
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, False, , , , lACCancel, , , True, True, lACPrint, True, True
    showPostButton
    FormWaitHide
Else
    RSZero
    FormSearch True
    SearchObj True
    Mode = Find
End If

End Sub

Public Sub TBAccountAffected()
    RepName = "DR"
    frmAccountAffected.mModuleType = KDR
    frmAccountAffected.mRefPK = txtDRNo.Text
    frmAccountAffected.Show vbModal
End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgDR.Name
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader
    
    showPostButton
End Sub

'Move previuos
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader
    
    showPostButton

End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader
    
    showPostButton
End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader

    showPostButton

End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbExclamation, msgTtl
        Exit Sub
    Else
        If (Trim(cboType) = "Others") Then
            If rsHeader!cDRNo = "" Then Exit Sub
            
            If dtgName = "dtgDR" Then
                rsDetail.AddNew
                rsDetail!cCompanyID = COID
                rsDetail!cDRNo = Trim(rsHeader!cDRNo)
                dtgDR.Col = 1
                dtgDR.Columns(1).Value = ""
                GetChild
                If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
                dtgDR.SetFocus
            End If
        Else: cmdLoad_Click            'Load details from list
        End If
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler

    If dtgName = dtgDR.Name Then
        If rsDetail.RecordCount = 0 Then rsHeader!nVatAmount = 0: Exit Sub
        vBookMark = dtgDR.Bookmark
        GetChild
        dtgDR.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
        ComputeTotal
    End If
    GetChild

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo All
Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    MsgBox "Unavailable on " & Me.Name

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Post current record
Public Sub TBPostRecord()
On Error GoTo TheSource
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Posting is not allowed", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If rsHeader!lApproved = True Then
        MsgBox "Transaction was already Posted.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to post this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub

    'Audit trail
    UpdateLogFile "Delivery Receipt", Trim(txtDRNo), "Posted"

    'Update PL Activity
    UpdateGLA "Update", "DR", Trim(txtDRNo)
    
    cn.Execute ("UPDATE DR SET lApproved = 1 ,  dUpdated = GETDATE () WHERE cDRNo = '" & Trim(txtDRNo) & "' AND cCompanyID = '" & COID & "'")
        
    sbRS.Panels(5) = "POSTED"
    Mode = Normal
    
    rsHeader!lPosted = True
    rsHeader.UpdateBatch adAffectAll
TheSource:
    If err.Number = -2147217885 Then
        Resume Next
    End If

    
End Sub

'Cancel current record
Public Sub TBCancelRecord()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled.", vbExclamation, msgTtl
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to cancel this record?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub

    If Not AllowDelete("Cancel") Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Delivery Receipt", Trim(txtDRNo), "Cancelled"
    cn.Execute ("UPDATE DR SET lCancelled = 1,  dUpdated = GETDATE ()  WHERE cDRNo = '" & Trim(txtDRNo) & "' AND cCompanyID = '" & COID & "'")
    
    UpdateGLA "Delete", "DR", Trim(txtDRNo)
    
    sbRS.Panels(5) = "CANCELLED"
    Mode = Normal
    
    rsHeader!lCancelled = True
    rsHeader.UpdateBatch adAffectAll
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Print
Public Sub TBPrintRecord()
    If Trim(txtDRNo) = "" Then Exit Sub
    If rsHeader!cdoctype <> "" Then
        RepName = GetValueFrTable("cParamName", "PARAMETER_USER", "cType = 'DRDOCTYPE' AND cValue = 'Doc 1'")
    Else: RepName = "BASIC_Delivery_Receipt_Trans"
    End If
    
    cModule = "Basic_Delivery_Receipt"
    oPrint.PrintReceipt Trim(txtDRNo)
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgDR.DataSource = rsDetail
    Set txtLongDesc.DataSource = rsDetail
End Sub

'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtDRNo.DataField = !cDRNo
        txtType.DataField = !cType
        dtbDate.DataField = !dDate
        dtbReceived.DataField = !dReceived
        dtbReturned.DataField = !dReturned
        txtType.DataField = !cType
        txtDelCode.DataField = !cDelCode
        txtRemarks.DataField = !cRemarks
        txtInvNo.DataField = !cInvNo
        txtODI.DataField = !cODINo
        txtProject.DataField = !cProjectID
        txtWork.DataField = !cWorkID
    End With
End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler

    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        'Status bar setup
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount

        If rsHeader.Status <> adRecNew Then
            txtDRNo.Locked = True
        Else: txtDRNo.Locked = False
        End If

        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
        
        GetChild
        
        If rsHeader!lCancelled = True Then
            sbRS.Panels(5) = "CANCELLED"
        Else
            sbRS.Panels(5) = ""
        End If
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtDRNo.Locked = False
    End If

    If Mode = AddNewEdit Then
        dtgDR.Refresh
    End If

ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else: SSTab1.TabEnabled(1) = True
    End If
End Sub

Private Sub txtDelCode_Change()
    txtDelName = ""
    Select Case Trim(cboType)
        Case "Supplier", "Production-OS", "Production-Int"
            txtDelName = GetValueFrTable("cName", "CLIENT_SUPPLIER", "cCode = '" & Trim(txtDelCode) & "'")
        Case Else
            txtDelName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtDelCode) & "'")
    End Select
    
    If Mode <> AddNewEdit Then Exit Sub
    If rsHeader.Status <> adRecNew Then Exit Sub
    If txtDelName <> "" Then
        If (UCase(Trim(cboType)) = "ISSUES") Or (UCase(Trim(cboType)) = "SALES") Then DRCreditLimitOK
    End If
End Sub

Private Sub txtDelCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtDelName) = "" And Trim(txtDelCode) <> "" Then cmdPickDelCode_Click
End Sub

Private Sub txtFreightAllow_Change()
    ComputeTotal
End Sub

Private Sub txtFreightCharges_Change()
    ComputeTotal
End Sub

Private Sub txtLongDesc_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txtLongDesc_LostFocus()
    txtLongDesc.Visible = False
    dtgDR.Col = 3
    dtgDR.SetFocus
End Sub

Private Sub txtDRNo_LostFocus()
    'Does Code Already Exist
    If Mode = AddNewEdit Then
        If Trim(txtDRNo) = "" Then
            MsgBox "Empty primary input.", vbInformation, msgTtl
            If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
            txtDRNo.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtDRNo = Trim(txtDRNo)
            If IDExisting(rsHeader, "cDRNo", "DR", Trim(rsHeader!cDRNo)) Then
                MsgBox "Delivery receipt No. already exist.", vbInformation, msgTtl
                If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
                txtDRNo.SetFocus
            End If
        End If
    End If
End Sub

Private Sub txtType_Change()
    If Trim(txtType) <> "" Or txtType <> vbNullString Then
        cboType = Trim(txtType)
    Else: cboType.ListIndex = -1
    End If
    
    If Mode = AddNewEdit Then
        txtDelCode = ""
    End If
    
    txtDelCode_Change
    
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean
    MandatoryOK = True
    If Trim(txtDRNo) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Receipt Number' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtDRNo.SetFocus
        Exit Function
    End If
    
    ComputeAmount
    ComputeTotal
    
    If rsHeader.Status = adRecNew And lSystemGenerated = False Then
        If IDExisting(rsHeader, "cDRNo", "DR", Trim(rsHeader!cDRNo)) Then
            MandatoryOK = False
            MsgBox "Delivery reciept No. already exist.", vbInformation, msgTtl
            txtDRNo.SetFocus
            Exit Function
        End If
    End If

    'Required fields
    If Trim(dtbDate.Text) = "__/__/____" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Date' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        dtbDate.SetFocus
        Exit Function
    ElseIf Trim(txtType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Type' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        cboType.SetFocus
        Exit Function
    ElseIf Trim(txtDelCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Client' is mandatory. Null value is not allowed.", vbInformation, msgTtl
        txtDelCode.SetFocus
        Exit Function
    End If
    
    GetChild
    
    'Transaction without details
    If rsDetail.RecordCount < 1 Then
        MandatoryOK = False
        MsgBox "Cannot save transaction without details.", vbInformation, msgTtl
        dtgDR.SetFocus
        Exit Function
    End If
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail!cWH = "" Then
            MandatoryOK = False
            MsgBox "Warehouse is required.", vbInformation, msgTtl
            Exit Function
        End If
        rsDetail.MoveNext
    Loop
    
    GetChild
            
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else: rsDetail.MoveNext
            End If
        Else: rsDetail.MoveNext
        End If
    Loop

    GetChild

    If rsDetail.RecordCount < 1 Then
        MsgBox "Cannot save transaction without details.", vbExclamation, msgTtl
        MandatoryOK = False
        Exit Function
    End If

    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.EOF
            rsDetail!nIdentity = rsDetail.AbsolutePosition
            rsDetail.MoveNext
        Loop
    End If
End Function

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsDetail.Filter = "cDRNo = '" & Trim(rsHeader!cDRNo) & "'"
End Sub

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    sbRS.Panels(4) = ""
    sbRS.Panels(5) = ""
    
    Set dtgDR.DataSource = Nothing
    dtgDR.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtDRNo.Locked = False
    txtDRNo.SetFocus
    
    Mode = Find
    
End Sub

Sub SearchObj(lEnable As Boolean)
    dtbDate.Enabled = lEnable
    cboType.Enabled = lEnable
    cmdPickDelCode.Enabled = lEnable
    cmdPickProject.Enabled = lEnable
    cmdPickWork.Enabled = lEnable
End Sub

'Add DR Detals from picklist to details recordset
Public Sub AddDetailsFromList()
    
    GetChild
    
    With frmRefList.lvwList
        For i = 1 To .ListItems.Count
            If .ListItems(i).Checked = True Then
                rsDetail.AddNew
                rsDetail!cCompanyID = COID
                rsDetail!cDRNo = Trim(rsHeader!cDRNo)
                rsDetail!cRefNo = Trim(frmRefList.mRefPK)
                rsDetail!cItemNo = IIf((Trim(.ListItems(i).Text) = "Other Item"), "", Trim(.ListItems(i).Text)) & "" 'Trim(.ListItems(i).Text)
                rsDetail!cDesc = Trim(.ListItems(i).SubItems(1))
                rsDetail!cWH = Trim(.ListItems(i).SubItems(2))

                rsDetail!cUnit = Trim(.ListItems(i).SubItems(3))
                rsDetail!nQty = CDbl(.ListItems(i).SubItems(4))
                rsDetail!nPrice = CDbl(.ListItems(i).SubItems(5))
                rsDetail!nAmount = CDbl(.ListItems(i).SubItems(6))
                rsDetail!nRefIdentity = CDbl(.ListItems(i).SubItems(7))
                rsDetail!cCosting = Trim(GetValueFrTable("cCosting", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
                'COSTING
                rsDetail!nCost = CDbl(.ListItems(i).SubItems(9))
                rsDetail!nFactor = CDbl(.ListItems(i).SubItems(8))
            End If
        Next i
    
        If rsDetail.RecordCount <> 0 Then
            sSQL = "Select lVatInclusive, nVATRate, cTaxType from SO where cSONo = '" & Trim(rsDetail!cRefNo) & "'"
            Set rs = New Recordset
            rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
            cn.CommandTimeout = 120
        
            If rs.RecordCount <> 0 Then
                rsHeader!lVatinclusive = rs!lVatinclusive
                rsHeader!nVatRate = rs!nVatRate
                rsHeader!cTaxType = rs!cTaxType
            End If
        End If
    End With

    GetChild
'    GetBarcode
    ComputeAmount
    ComputeTotal

End Sub

'Computes total amount per detail line
Private Sub ComputeAmount()
Dim nAmount As Double
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    dtgDR.Bookmark = 1
    With dtgDR
        nAmount = IIf(IsNull(.Columns(6).Value), 0, .Columns(6).Value) * _
                    IIf(IsNull(.Columns(7).Value), 0, .Columns(7).Value)
        .Columns(8).Text = Format(nAmount, "###,##0.#0")
    End With
End Sub

'Gross amount
Public Sub ComputeTotal()
Dim n, m As Double
    
On Error Resume Next
    
    If Mode <> AddNewEdit Then Exit Sub
    
    m = 0
    n = 0
    Set rs = New Recordset
    
    Set rs = rsDetail.Clone
    rs.Filter = "cDRNo = '" & Trim(rsHeader!cDRNo) & "'"

    rs.MoveFirst
    sSQL = "Select lVatInclusive, nVATRate from SO where cSONO= '" & Trim(rs!cRefNo) & "'"
    
    Do Until rs.EOF
        n = n + IIf(IsNull(rs!nAmount), 0, rs!nAmount)
        rs.MoveNext
    Loop
    
    Set rs = Nothing
    If rsHeader!lVatinclusive Then
        m = n * (1 - (1 / (1 + rsHeader!nVatRate / 100)))
    Else: m = n * (rsHeader!nVatRate / 100)
    End If

    rsHeader!nGross = IIf(rsHeader!lVatinclusive, n, n + m)
    rsHeader!nVAT = Round(m, 2)
End Sub

'Inserts into SALES & SALES_T tables
Private Function DRSales() As Boolean
Dim rsSales As New ADODB.Recordset
Dim rsSales_T As New ADODB.Recordset
Dim cSO, cSO_T As String
Dim nSO_I As Long

On Error GoTo DRSalesExit
    
    DRSales = False

    cString = "DR-" & Trim$(rsHeader!cDRNo)
    cSO = rsDetail!cRefNo
    rsHeader!cInvNo = Trim(cString)
    
    'FOR REVISION [DO NOT DELETE BECAUSE OF THE IDENTITY] ???????????
    cn.Execute ("DELETE SALES_T WHERE cCompanyID = '" & COID & "' AND cInvNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE SALES WHERE cCompanyID = '" & COID & "' AND cInvNo = '" & Trim(cString) & "'")
    
    GetChild
    
    OpenRecordset rsSales, "*", "SALES", "WHERE 1 = 0"
    OpenRecordset rsSales_T, "*", "SALES_T", "WHERE 1 = 0"
    
    With rsSales
        .AddNew
        !cCompanyID = COID
        !cInvNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cType = "Auto-Invoice"
        !cCode = Trim(rsHeader!cDelCode)
        !cMSCode = GetValueFrTable("cMSCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(rsHeader!cDelCode) & "'")
        !cPDCode = GetValueFrTable("cPDCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(rsHeader!cDelCode) & "'")
        !cSMan = GetValueFrTable("cSMan", "CLIENT_CUSTOMER", "cCode = '" & Trim(rsHeader!cDelCode) & "'")
        !cTerm = GetValueFrTable("cTerm", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cIntTerm = GetValueFrTable("cIntTerm", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cPayType = "Credit"
        !nGross = rsHeader!nGross
        !nBalance = rsHeader!nGross
        !cRemarks = "Auto-Invoice for " & Trim(rsHeader!cType)
    End With

    Do While Not rsDetail.EOF
        With rsSales_T
            .AddNew
            !cCompanyID = COID
            !cInvNo = Trim$(cString)
            !cRefNo = Trim$(rsHeader!cDRNo)
            !nRefIdentity = rsDetail!nIdentity
            !cWH = Trim$(rsDetail!cWH)
            !cItemNo = Trim$(rsDetail!cItemNo)
            !cDesc = Trim$(rsDetail!cDesc)
            !cUnit = Trim$(rsDetail!cUnit)
            !nQty = rsDetail!nQty
            !nPrice = rsDetail!nPrice
            !nAmount = rsDetail!nAmount
            !nCost = rsDetail!nCost
            !cCosting = rsDetail!cCosting
            !nFactor = rsDetail!nFactor
            
            cSO_T = rsDetail!cRefNo
            nSO_I = rsDetail!nRefIdentity
            !cPricing = GetValueFrTable("cPricing", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !nUDPrice = GetValueFrTable("nPrice", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !cDiscount = GetValueFrTable("cDiscount", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !nTPC = GetValueFrTable("nTPC", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !nSMCom = GetValueFrTable("nSMCom", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        End With
        rsDetail.MoveNext
    Loop

    rsSales.UpdateBatch adAffectAll
    rsSales_T.UpdateBatch adAffectAll
    
    Set rsSales = Nothing
    Set rsSales_T = Nothing
    
    DRSales = True
    
DRSalesExit:
    Exit Function
    
End Function

'Inserts into SALES & SALES_T tables
Private Function DRSalesEmp() As Boolean
Dim rsSales As New ADODB.Recordset
Dim rsSales_T As New ADODB.Recordset
Dim cSO, cSO_T As String
Dim nSO_I As Long

On Error GoTo DRSalesExit
    
    DRSalesEmp = False

    cString = "DR-" & Trim$(rsHeader!cDRNo)
    cSO = rsDetail!cRefNo
    rsHeader!cInvNo = Trim(cString)
    
    'FOR REVISION [DO NOT DELETE BECAUSE OF THE IDENTITY] ???????????
    cn.Execute ("DELETE SALES_T WHERE cCompanyID = '" & COID & "' AND cInvNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE SALES WHERE cCompanyID = '" & COID & "' AND cInvNo = '" & Trim(cString) & "'")
    
    GetChild
    
    OpenRecordset rsSales, "*", "SALES", "WHERE 1 = 0"
    OpenRecordset rsSales_T, "*", "SALES_T", "WHERE 1 = 0"
    
    With rsSales
        .AddNew
        !cCompanyID = COID
        !cInvNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cType = "Employee"
        !cCode = Trim(rsHeader!cDelCode)
        !cMSCode = GetValueFrTable("cMSCode", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cSMan = GetValueFrTable("cSMan", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cTerm = GetValueFrTable("cTerm", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cIntTerm = GetValueFrTable("cIntTerm", "SO", "cSONo = '" & Trim(cSO) & "'")
        !cPayType = "Credit"
        !nGross = rsHeader!nGross
        !nBalance = rsHeader!nGross
    End With

    Do While Not rsDetail.EOF
        With rsSales_T
            .AddNew
            !cCompanyID = COID
            !cInvNo = Trim$(cString)
            !cRefNo = Trim$(rsHeader!cDRNo)
            !nRefIdentity = rsDetail!nIdentity
            !cWH = Trim$(rsDetail!cWH)
            !cItemNo = Trim$(rsDetail!cItemNo)
            !cDesc = Trim$(rsDetail!cDesc)
            !cUnit = Trim$(rsDetail!cUnit)
            !nQty = rsDetail!nQty
            !nPrice = rsDetail!nPrice
            !nAmount = rsDetail!nAmount
            !nCost = rsDetail!nCost
            !cCosting = rsDetail!cCosting
            !nFactor = rsDetail!nFactor
            
            cSO_T = rsDetail!cRefNo
            nSO_I = rsDetail!nRefIdentity
            !cPricing = GetValueFrTable("cPricing", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !nUDPrice = GetValueFrTable("nPrice", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !cDiscount = GetValueFrTable("cDiscount", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !nTPC = GetValueFrTable("nTPC", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
            !nSMCom = GetValueFrTable("nSMCom", "SO_T", "cSONo = '" & Trim(cSO) & "' AND nIdentity = '" & nSO_I & "'")
        End With
        rsDetail.MoveNext
    Loop

    rsSales.UpdateBatch adAffectAll
    rsSales_T.UpdateBatch adAffectAll
    
    Set rsSales = Nothing
    Set rsSales_T = Nothing
    
    DRSalesEmp = True
    
DRSalesExit:
    Exit Function
    
End Function

'Update reference number in Production_FG table (Production-Int & Production-OS)
Sub Update_Prod_RefNo(DRNo As String)
Dim RefPONo As String
    
    GetChild
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        RefPONo = rsDetail!cRefNo
    
        cn.Execute "UPDATE PRODUCTION SET lRRReady = 1, cDRNo = '" & DRNo & "' WHERE cTranNo = '" & Trim(RefPONo) & "' " & _
                    "AND cCompanyID = '" & COID & "'"
        rsDetail.MoveNext
    Loop
    
End Sub

Private Function AllowEdit() As Boolean
    AllowEdit = True
    
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot edit transaction with invoice/collection.", vbCritical + vbExclamation, msgTtl
        AllowEdit = False
        Exit Function
    ElseIf Trim(txtInvNo) <> "" Then
        MsgBox "Cannot edit transaction with invoice.", vbCritical + vbExclamation, msgTtl
        AllowEdit = False
        Exit Function
    End If
    
End Function

Private Function AllowDelete(sAction As String) As Boolean
    AllowDelete = True
    
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot " & sAction & " transaction with invoice/collection.", vbCritical + vbExclamation, msgTtl
        AllowDelete = False
        Exit Function
    End If

    'Delete existing reference sales invoice for this transaction
    If UCase(Trim(cboType)) = "PRODUCTION-INT" Then
        cn.Execute ("UPDATE PRODUCTION SET cDRNo = NULL, lRRReady = 0 WHERE cDRNo = '" & Trim$(rsHeader!cDRNo) & "' AND cCompanyID = '" & COID & "'")
    ElseIf UCase(Trim(cboType)) = "PRODUCTION-OS" Then
        cn.Execute ("UPDATE PRODUCTION SET cDRNo = NULL, lRRReady = 0 WHERE cDRNo = '" & Trim$(rsHeader!cDRNo) & "' AND cCompanyID = '" & COID & "'")
    End If
    
End Function

Sub EditDetail(bval As Boolean)

    If UCase$(Trim$(cboType)) = "REPLACEMENT" Then
        dtgDR.Columns(6).Locked = bval
    Else: dtgDR.Columns(6).Locked = Not bval
    End If
    
    If UCase$(Trim$(cboType)) = "SALES" Then
        dtgDR.Columns(7).Locked = Not bval
    ElseIf UCase$(Trim$(cboType)) = "TRANSFER" Then
        dtgDR.Columns(7).Locked = Not bval
    Else: dtgDR.Columns(7).Locked = bval
    End If

End Sub

'Checks the credit status of the client
Function DRCreditLimitOK() As Boolean
Dim sCode, sPCCode As String
Dim lCHold As Boolean
    
    If Not GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CL_CHECKING_DR'") Then
        DRCreditLimitOK = True
        Exit Function
    End If
    
    MousePointer = vbHourglass
    FormWaitShow App.Path & "\Transmit.avi", "Checking Credit Limit Balance . . ."

    sCode = Trim(txtDelCode)
    
    cn.CommandTimeout = 600
    If Not GetValueFrTable("lGroupLimit", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'") Then
        'Query for independent client
        sSQL = "SELECT cCompanyID, cCode, SUM(nLimit) AS nLimit, SUM(nAR) AS nAR, SUM(nARPastDue) AS nARPastDue, " & _
                "SUM(nPDC) AS nPDC, SUM(CAST(lHold AS INT)) AS nHold, SUM(nBounced) AS nBounced, " & _
                "SUM(nSOAmtLeft) AS nSOAmtLeft, SUM(nLimitBalance) AS nLimitBalance " & _
                "From V_CG " & _
                "WHERE cCode = '" & sCode & "' AND cCompanyID = '" & COID & "'" & _
                "GROUP BY cCompanyID, cCode"
    Else
        sPCCode = GetValueFrTable("cGroupCode", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'")
        lCHold = GetValueFrTable("lHold", "CLIENT_CUSTOMER", "cCode = '" & sCode & "'")
        'Query for customer affecting parent company
        sSQL = "SELECT cCompanyID, cGroupCode, SUM(nLimit) AS nLimit, SUM(nAR) AS nAR, SUM(nARPastDue) AS nARPastDue, " & _
                "SUM(nPDC) AS nPDC, " & IIf(lCHold, "1", "0") & " AS nHold, SUM(nBounced) AS nBounced, " & _
                "SUM(nSOAmtLeft) AS nSOAmtLeft, SUM(nLimit - nAR - nPDC - nSOAmtLeft) AS nLimitBalance " & _
                "From V_CG_PC " & _
                "WHERE cGroupCode = '" & sPCCode & "' AND cCompanyID = '" & COID & "'" & _
                "GROUP BY cCompanyID, cGroupCode"
    End If
    
    Set rs = New Recordset
    rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    cn.CommandTimeout = 120
    
    If rs.RecordCount > 0 Then
        nLimit = rs!nLimit
        nAR = rs!nAR
        nARPastDue = rs!nARPastDue
        nPDC = rs!nPDC
        nHold = rs!nHold
        nBounced = rs!nBounced
        nSOAmtLeft = rs!nSOAmtLeft
        nLimitBalance = rs!nLimitBalance
    Else
        nLimit = 0
        nAR = 0
        nARPastDue = 0
        nPDC = 0
        nHold = 0
        nBounced = 0
        nSOAmtLeft = 0
        nLimitBalance = 0
    End If
    
    'Is Credit OK?
    Dim cHold, cOCL, cPDAR, cRTC As String
    
    DRCreditLimitOK = True
    If nHold > 0 Then
        cHold = "Customer on Hold"
        DRCreditLimitOK = False
    End If
    If nLimitBalance < 0 Then
        cOCL = "Over Credit Limit [Php " & Format((-1 * nLimitBalance), "#,##0.#0") & "]"
        DRCreditLimitOK = False
    End If
    If nARPastDue > 0 Then
        cPDAR = "With Past Due A/R [Php " & Format(nARPastDue, "#,##0.#0") & "]"
        DRCreditLimitOK = False
    End If
    If nBounced > 0 Then
        cRTC = "With Bounced Check"
        DRCreditLimitOK = False
    End If

    FormWaitHide
    MousePointer = vbDefault
    
    lOverride = False
    
    If Not DRCreditLimitOK Then
        MsgBox "Cannot proceed transaction with customer " & sCode & " due to following reason/s:" & vbCr & _
               cHold & IIf((cOCL <> ""), " | " & cOCL, "") & _
               IIf((cPDAR <> ""), " | " & cPDAR, "") & _
               IIf((cRTC <> ""), " | " & cRTC, ""), vbCritical, Me.Caption
        If nBounced = 0 Then
            RepName = Trim(txtDRNo)
            frmOverride.mOverridingType = O_DR
            frmOverride.Show vbModal
            If gAction = G_OK Then
                cmdPickDelCode.SetFocus
                lOverride = True
                Exit Function
            Else
                txtDelCode = ""
                txtDelCode.SetFocus
            End If
        Else
            txtDelCode = ""
            txtDelCode.SetFocus
        End If
    End If
    
End Function

'Item Balance per warehouse
Function BalancePerWarehouseOK() As Boolean
    Set rs = New Recordset
        
    BalancePerWarehouseOK = True
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else: rsDetail.MoveNext
            End If
        Else: rsDetail.MoveNext
        End If
    Loop

    GetChild
    cString = Empty
    rsDetail.MoveFirst
    Do Until rsDetail.EOF
        sSQL = "SELECT (ISNULL(B.nInitial, 0) + A.nIncoming - A.nOutgoing + A.nRetSales - A.nRetPur - A.nIssues + " & _
                "A.nBack - A.nProdOut + A.nProdIn + A.nAdjustment - A.nSampleDemo) AS nBalance " & _
                "FROM V_ProductBalanceInquiry_WH A " & _
                "FULL OUTER JOIN ITEM_W B ON A.cCompanyID = B.cCompanyID AND A.cItemNo = B.cItemNo AND A.cWH = B.cWH " & _
                "WHERE A.cItemNo = '" & rsDetail!cItemNo & "' AND A.cCompanyID = '" & COID & "' AND A.cWH = '" & rsDetail!cWH & "' " & _
                "GROUP BY A.cCompanyID, A.cItemNo, A.cWH, A.nIncoming, A.nOutgoing, A.nRetSales, A.nRetPur, A.nIssues, A.nBack, A.nProdOut, " & _
                "A.nProdIn , A.nReserved, A.nAdjustment, A.nSampleDemo, B.nInitial"
        rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
        If rs.RecordCount > 0 Then
            If rs!nBalance < rsDetail!nQty Then
                cString = cString & vbCr & rsDetail!cItemNo & " WH: " & rsDetail!cWH & " Bal: " & Format(rs!nBalance, " #,##0.#0") & " Qty: " & Format(rsDetail!nQty, " #,##0.#0")
            End If
        End If
        rs.Close
        rsDetail.MoveNext
    Loop
    
    Set rs = Nothing
    
    If Trim(cString) <> "" Then
        If MsgBox("Product balance per warehouse alert!" & vbCr & cString & vbCr & vbCr & _
                "Do you want to proceeed on saving this transaction?", vbYesNo + vbInformation, "iTG Finace Manager") = vbNo Then BalancePerWarehouseOK = False
    End If
    
    rsDetail.MoveFirst
    cString = Empty

End Function

'Gets initital item values
Private Sub GetInitialItemValues(RefRS As Recordset)
    RefRS!cDesc = Trim(GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cUnit = Trim(GetValueFrTable("cUnit", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cWH = Trim(GetValueFrTable("cWH", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!nPrice = Trim(GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!nCost = IIf(GetValueFrTable("nAveCost", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'") = "", 0, GetValueFrTable("nAveCost", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'"))
    RefRS!nQty = 0
End Sub

Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtDRNo.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cDrNo LIKE '" & Trim$(txtDRNo.Text) & "%'"
    If Trim$(dtbDate.Text) <> "__/__/____" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dDate = '" & Trim$(dtbDate.Text) & "'"
    If Trim$(txtType.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cType LIKE '" & Trim$(txtType.Text) & "%'"
    If Trim$(txtDelCode.Text) <> "" Then sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cDelCode LIKE '" & Trim$(txtDelCode.Text) & "%'"
    
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

'Change Transaction Number
Sub ChangeTranNo(strTranNo As String)
    GetChild
    
    rsHeader!cDRNo = strTranNo
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        rsDetail!cDRNo = strTranNo
        rsDetail.MoveNext
    Loop
    
    GetChild
End Sub

Public Sub showPostButton()
    If cboType.Text = "Consignment" Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , True, lACCancel, , , True, True, lACPrint, True, True
    Else: BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True
    End If
End Sub

'Public Sub ShowForm(sTranNo As String)
'    If Mode = Find Then
'
'        OpenNewConnection connHeader
'        OpenNewConnection connDetail
'
'        Set rsHeader = Nothing
'        Set rsDetail = Nothing
'        Set rsHeader = New ADODB.Recordset
'        Set rsDetail = New ADODB.Recordset
'
'        OpenRecordsetWithCN rsDetail, "*", "DR_T", connDetail, "WHERE cDRNo = '" & Trim(sTranNo) & "'"
'        OpenRecordsetWithCN rsHeader, "*", "DR", connHeader, "WHERE cDRNo = '" & Trim(sTranNo) & "'"
'
'        Set FrmName = Me
'        FormLocking True
'
'        If rsHeader.RecordCount = 0 Then
'            FormWaitHide
'            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
'            RSZero
'            FormSearch True
'            SearchObj True
'            Mode = Find
'            Exit Sub
'        End If
'            SetDataSource
'            SetDataField
'            txtDRNo.BackColor = &HE0FFFF
'            Mode = Normal
'            oBar.BitEnabled Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True
'
'    End If
'End Sub

Private Sub GetBarcode()
Dim rsGetBarcode As New ADODB.Recordset
Dim CustType As String

CustType = GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cDelCode & "'")

    Set rsGetBarcode = New ADODB.Recordset
    If GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cDelCode & "'") = "Consignee" Then
        rsDetail!cBarcodeID = GetValueFrTable("cBarcode", "ITEM_UNIT", "cItemNo = '" & rsDetail!cItemNo & "' and cType = '" & Trim(CustType) & "' and cRefID = '" & Trim(rsHeader!cDelCode) & "' and cType = 'Consignee'")
        rsDetail!nPrice = GetValueFrTable("nPrice", "ITEM_UNIT", "cItemNo = '" & rsDetail!cItemNo & "' and cBarcode = '" & Trim(rsDetail!cBarcodeID) & "' and cRefID = '" & Trim(rsHeader!cDelCode) & "' and cType = 'Consignee'")
    Else
        If IDExisting(rsGetBarcode, "cType", "ITEM_UNIT", Trim(CustType), "cItemNo = '" & rsDetail!cItemNo & "'") = True Then
            rsDetail!cBarcodeID = GetValueFrTable("cBarcode", "ITEM_UNIT", "cItemNo = '" & rsDetail!cItemNo & "' and cType = '" & Trim(CustType) & "'")
            rsDetail!nPrice = GetValueFrTable("nPrice", "ITEM_UNIT", "cItemNo = '" & rsDetail!cItemNo & "' and cBarcode = '" & Trim(rsDetail!cBarcodeID) & "'")
        Else
            rsDetail!cBarcodeID = ""
            rsDetail!nPrice = 0
        End If
    End If
End Sub


Private Sub txtProject_Change()
    txtProjectName = ""
    txtProjectName = GetValueFrTable("cProjectName", "Project_Maintenance", "cProjectNo = '" & Trim(txtProject) & "'")
End Sub


Private Sub txtProject_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtProject) = "" And Trim(txtProject) <> "" Then cmdPickProject_Click
End Sub

Private Sub cmdPickProject_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtProject)
    frmITGPicker.zType = QProject
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
    
    frmITGPicker.Show vbModal
    txtProject = frmITGPicker.zCode
    txtProjectName = frmITGPicker.zName
    If Trim(txtProjectName) <> "" Then SendKeys "{Tab}"
End Sub



Private Sub txtWork_Change()
    txtWorkDesc = ""
    If txtProject.Text = "" Then: txtProject.SetFocus: Exit Sub
    txtWorkDesc = GetValueFrTable("description", "Work_Maintenance_File", "workno = '" & Trim(txtWork) & "' ") 'and cProjectNo =  '" & Trim(txtProject) & "'")
End Sub


Private Sub cmdPickWork_Click()
    If lPickListActive Then Exit Sub
'    sFilterString = Trim(txtWork)
    frmITGPicker.zType = QWork
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "' " 'and cProjectNo = '" & Trim(txtProject) & "'"
    
    frmITGPicker.Show vbModal
    txtWork = frmITGPicker.zCode
    txtWorkDesc = frmITGPicker.zName
    If Trim(txtWorkDesc) <> "" Then SendKeys "{Tab}"
End Sub


Private Sub txtWork_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtWork) = "" And Trim(txtWork) <> "" Then cmdPickWork_Click
End Sub
